package com.jie.netty.im.tactics.impl;

import com.jie.constants.ChannelAttrKey;
import com.jie.netty.im.tactics.HeartbeatTimeoutHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.util.AttributeKey;
import lombok.extern.slf4j.Slf4j;

/**
 * 房间心跳超时处理类
 */
@Slf4j
public class RoomHeartbeatTimeoutHandler implements HeartbeatTimeoutHandler {

    @Override
    public void handleTimeout(ChannelHandlerContext ctx) {
        AttributeKey<String> attr = AttributeKey.valueOf(ChannelAttrKey.USER_NAME);
        String username = ctx.channel().attr(attr).get();
        AttributeKey<String> roomAttr = AttributeKey.valueOf(ChannelAttrKey.ROOM_ID);
        String roomId = ctx.channel().attr(roomAttr).get();
        log.info("房间心跳超时，即将断开连接,用户:{},房间号:{} ", username, roomId);
    }
}